package com.itheima.web;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.itheima.dto.AnswerDto;
import com.itheima.servcie.TestSoulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/testSoul")
public class TestSoulController {
    @Autowired
    private TestSoulService testSoulService;

    /**
     * 问卷列表
     * @return
     */
    @GetMapping
    public ResponseEntity questions(){
        return ResponseEntity.ok(testSoulService.getQuestions());
    }

    /**
     * 提交问卷
     * @return
     */
    @PostMapping
    public ResponseEntity answers(@RequestBody Map answers){
        List<AnswerDto> answerDtos = (List<AnswerDto>) answers.get("answers");
        return ResponseEntity.ok(testSoulService.answers(answerDtos));
    }

    /**
     * 查看报告
     * @param id
     * @return
     */
    @GetMapping("/report/{id}")
    public ResponseEntity report(@PathVariable Integer id){
        return ResponseEntity.ok(testSoulService.report(id));
    }
}
